package com.jinmdz.fmis.api.api.service;

import com.jinmdz.fmis.api.api.model.transport.TransportCarCodeData;
import com.jinmdz.fmis.api.base.BaseService;
import com.jinmdz.fmis.core.base.BaseResult;
import com.jinmdz.fmis.dao.dao.TransportCarDao;
import com.jinmdz.fmis.dao.model.transport.TransportCarItem;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.ArrayList;

/**
 * TransportCarService类
 *
 * @author LiCongLu
 * @date 2020-01-20 10:20
 */
@Service("transportCarService")
public class TransportCarService extends BaseService {

    @Resource
    private TransportCarDao transportCarDao;

    /**
     * 根据车辆类型加载transport_car表中车辆信息
     *
     * @param data 车辆类型代码
     * @return
     * @author LiCongLu
     * @date 2020-02-11 15:13
     */
    public BaseResult<ArrayList<TransportCarItem>> loadTransportCarWithTypeCode(TransportCarCodeData data) {
        Integer typeCode = data.getTypeCode();
        Integer oldCarId = data.getOldCarId();

        // 查询数据
        ArrayList<TransportCarItem> loadItems = new ArrayList<TransportCarItem>();
        //传旧的车辆id用下面的查询方法，只查车型，用上面的查询
        if (oldCarId == null) {
            loadItems = transportCarDao.listTransportCarByTypeCode(typeCode);
        } else {
            loadItems = transportCarDao.listTransportCarByTypeCodeAndOldCarId(typeCode, oldCarId);
        }

        // 返回响应结果
        return successList(loadItems);
    }
}
